package com.gskj.gulimall.seckill.conf;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @ClassName MyRedissonConfig
 * @Description TODO
 * @Author 康纳
 * @Date 2021-02-16
 */


@Configuration
public class MyRedissonConfig {

    /***
     *  所有对redisson的使用，都是通过 RedissonClient 对象
     *  destroyMethod = "shutdown" 服务停止后，销毁
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient client() throws IOException {
        // 创建配置
        Config config = new Config();
        // TODO 早springboot创建实例时，报错:Redis url should start with redis:// or rediss:// (for SSL connection)
        // 设置 redis ip地址
        config.useSingleServer().setAddress("redis://192.168.3.26:6379");
        // 创建实例
        return Redisson.create(config);
    }
}
